﻿<div class="layui-card">
	<div class="layui-card-body">
		<table id="tblList" lay-filter="tblList"></table>
		<script type="text/html" id="toolbarHead">
			<div class="layui-form-item" style="margin: auto;">
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" onclick="layer_show('添加会员组','/Admin/User/UserGroupEdit')">添加会员组</button>
				</div>
			</div>
		</script>
		<script type="text/html" id="tblBarPermissions">
			<a class="layui-btn layui-btn-xs" lay-event="perm">常规权限设置</a>
			<a class="layui-btn layui-btn-xs" lay-event="frontPerm">前台权限设置</a>
			<a class="layui-btn layui-btn-xs" lay-event="upgrade">会员组升级设置</a>
		</script>
		<script type="text/html" id="tblBarCol">
			<a class="layui-btn layui-btn-xs" lay-text="{{d.GroupName}}成员" lay-href="/Admin/User/UserManage?GroupID={{d.GroupID}}"><i class="layui-icon layui-icon-group"></i>成员</a>
			<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
	</div>
</div>
@Html.AntiForgeryToken()
@section scripts {
<script type="text/javascript">
	layui.use(['table'], function () {
		var table = layui.table;

		//加载表格
		table.render({
			elem: '#tblList'
			, url: '/Admin/User/GetUserGroupManage'
			, toolbar: '#toolbarHead'
			, request: {
				pageName: 'PageNum' //页码的参数名称，默认：page
				, limitName: 'PageSize' //每页数据量的参数名，默认：limit
			}
			, cols: [[
				{ field: 'GroupID', width: 50, title: 'ID', align: 'center' },
				{ field: 'GroupName', width: 150, title: '会员组名', align: 'center' },
				{ field: 'Description', maxWidth: 200, title: '会员组简介', align: 'center' },
				{ field: 'GroupTypeName', width: 100, title: '组类型', align: 'center' },
				{ field: 'UserInGroupNumber', width: 100, title: '会员数量', align: 'center' },
				{ field: 'GroupID', width: 350, title: '权限设置', align: 'center', templet: '#tblBarPermissions' },
				{ field: 'GroupID', width: 230, title: '管理操作', align: "center", templet: '#tblBarCol' }
			]]
			, parseData: function (res) { //res 即为原始返回的数据
				return {
					"code": 0, //解析接口状态
					"msg": "", //解析提示文本
					"count": res.RecordTotal, //解析数据长度
					"data": res.RowList //解析数据列表
				};
			}
			, limits: [10, 15, 20, 25, 50, 100]
			, limit: 15
			, page: true
		});
		//监听表格操作列
		table.on('tool(tblList)', function (obj) {
			if (obj.event === 'edit') {
				layer_show('编辑会员组', '/Admin/User/UserGroupEdit?id=' + obj.data.GroupID);
				return false;
			} else if (obj.event === 'del') {
				DeleteSingle(obj.data.GroupID, "/Admin/User/DelUserGroup");
				return false;
			} else if (obj.event === 'perm') {
				layer_show('常规权限设置', '/Admin/User/UserGroupPermissions?id=' + obj.data.GroupID + '&IdType=1');
				return false;
			} else if (obj.event === 'frontPerm') {
				layer_show('前台权限设置', '/Admin/User/UserGroupFrontPermissions?id=' + obj.data.GroupID + '&IdType=1');
				return false;
			} else if (obj.event === 'upgrade') {
				layer_show('会员组升级设置', '/Admin/User/UserGroupUpgradeSetting?id=' + obj.data.GroupID + '&groupName='+obj.data.GroupName);
				return false;
			}
		});
		//表格重载
		function reloadTable(tableID = 'tblList') {
			table.reload(tableID, {
				page: {
					curr: 1
				}
			}, 'data');
		};
	});
</script>
}